﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BoletoElectronicoDesktop.AbmBeneficiarios
{
    public partial class FormBajaBeneficiarios : Form
    {
        public string rubro;
        public FormBajaBeneficiarios()
        {
            InitializeComponent();
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void FormBajaBeneficiarios_Load(object sender, EventArgs e)
        {
            //inicio con la ventana maximizada
            this.WindowState = FormWindowState.Maximized;



        }

        private void btnLimpiar_Click(object sender, EventArgs e)
        {
            //pongo todos los textBox en blanco
            txtRazonSocial.Text = "";
            txtCalle.Text = "";
            txtNum.Text = "";
            txtPiso.Text = "";
            txtDepto.Text = "";
            txtPostNet.Text = "";
            comboRubro.DataSource = null;
            dataGridView1.DataSource = null;
        }

        private void comboRubro_Click(object sender, EventArgs e)
        {
            //cargo las rubros en el ComboBox
            DataTable rubros = BeneficiarioDAO.ObtenerRubros();
            comboRubro.DataSource = rubros;
            comboRubro.DisplayMember = "DescripcionRubro";
            comboRubro.ValueMember = "IdRubro";
        }

        private void btnSeleccionar_Click(object sender, EventArgs e)
        {
            FormSeleccionarPostnet form = new FormSeleccionarPostnet();
            form.ShowDialog(this);
            txtPostNet.Text = form.numeroPostnet;
        }

        private void btnBuscar_Click(object sender, EventArgs e)
        {
            if (comboRubro.Text == "")
                rubro = "";
            else
                rubro = comboRubro.SelectedValue.ToString();
            DataTable dt = BeneficiarioDAO.ObtenerBeneficiariosHabilitados(txtRazonSocial.Text, txtCalle.Text, txtNum.Text, txtPiso.Text, txtDepto.Text, txtPostNet.Text, rubro);
            dataGridView1.DataSource = dt;
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            BeneficiarioDAO.InhabilitarBeneficiario(dataGridView1.CurrentRow.Cells["BeneficiarioID"].Value.ToString());
            MessageBox.Show("Beneficiario eliminado con éxito");
            DataTable dt = BeneficiarioDAO.ObtenerBeneficiariosHabilitados(txtRazonSocial.Text, txtCalle.Text, txtNum.Text, txtPiso.Text, txtDepto.Text, txtPostNet.Text, rubro);
            dataGridView1.DataSource = dt;
        }
    }
}
